


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > LauncherSmokeTest</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman</a>
</div>

<h1>Coverage Summary for Class: LauncherSmokeTest (nl.tudelft.jpacman)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">LauncherSmokeTest</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/29)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package nl.tudelft.jpacman;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;import static org.assertj.core.api.Assertions.assertThat;
<i class="no-highlight">4</i>&nbsp;
<i class="no-highlight">5</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
<i class="no-highlight">6</i>&nbsp;import nl.tudelft.jpacman.game.Game;
<i class="no-highlight">7</i>&nbsp;import nl.tudelft.jpacman.level.Player;
<i class="no-highlight">8</i>&nbsp;import org.junit.jupiter.api.AfterEach;
<i class="no-highlight">9</i>&nbsp;import org.junit.jupiter.api.BeforeEach;
<i class="no-highlight">10</i>&nbsp;import org.junit.jupiter.api.Test;
<i class="no-highlight">11</i>&nbsp;
<i class="no-highlight">12</i>&nbsp;/**
<i class="no-highlight">13</i>&nbsp; * Smoke test launching the full game,
<i class="no-highlight">14</i>&nbsp; * and attempting to make a number of typical moves.
<i class="no-highlight">15</i>&nbsp; *
<i class="no-highlight">16</i>&nbsp; * This is &lt;strong&gt;not&lt;/strong&gt; a &lt;em&gt;unit&lt;/em&gt; test -- it is an end-to-end test
<i class="no-highlight">17</i>&nbsp; * trying to execute a large portion of the system&#39;s behavior directly from the
<i class="no-highlight">18</i>&nbsp; * user interface. It uses the actual sprites and monster AI, and hence
<i class="no-highlight">19</i>&nbsp; * has little control over what is happening in the game.
<i class="no-highlight">20</i>&nbsp; *
<i class="no-highlight">21</i>&nbsp; * Because it is an end-to-end test, it is somewhat longer
<i class="no-highlight">22</i>&nbsp; * and has more assert statements than what would be good
<i class="no-highlight">23</i>&nbsp; * for a small and focused &lt;em&gt;unit&lt;/em&gt; test.
<i class="no-highlight">24</i>&nbsp; *
<i class="no-highlight">25</i>&nbsp; * @author Arie van Deursen, March 2014.
<i class="no-highlight">26</i>&nbsp; */
<b class="nc"><i class="no-highlight">27</i>&nbsp;public class LauncherSmokeTest {</b>
<i class="no-highlight">28</i>&nbsp;
<i class="no-highlight">29</i>&nbsp;    private Launcher launcher;
<i class="no-highlight">30</i>&nbsp;
<i class="no-highlight">31</i>&nbsp;    /**
<i class="no-highlight">32</i>&nbsp;     * Launch the user interface.
<i class="no-highlight">33</i>&nbsp;     */
<i class="no-highlight">34</i>&nbsp;    @BeforeEach
<i class="no-highlight">35</i>&nbsp;    void setUpPacman() {
<b class="nc"><i class="no-highlight">36</i>&nbsp;        launcher = new Launcher();</b>
<b class="nc"><i class="no-highlight">37</i>&nbsp;        launcher.launch();</b>
<i class="no-highlight">38</i>&nbsp;    }
<i class="no-highlight">39</i>&nbsp;
<i class="no-highlight">40</i>&nbsp;    /**
<i class="no-highlight">41</i>&nbsp;     * Quit the user interface when we&#39;re done.
<i class="no-highlight">42</i>&nbsp;     */
<i class="no-highlight">43</i>&nbsp;    @AfterEach
<i class="no-highlight">44</i>&nbsp;    void tearDown() {
<b class="nc"><i class="no-highlight">45</i>&nbsp;        launcher.dispose();</b>
<i class="no-highlight">46</i>&nbsp;    }
<i class="no-highlight">47</i>&nbsp;
<i class="no-highlight">48</i>&nbsp;    /**
<i class="no-highlight">49</i>&nbsp;     * Launch the game, and imitate what would happen in a typical game.
<i class="no-highlight">50</i>&nbsp;     * The test is only a smoke test, and not a focused small test.
<i class="no-highlight">51</i>&nbsp;     * Therefore it is OK that the method is a bit too long.
<i class="no-highlight">52</i>&nbsp;     *
<i class="no-highlight">53</i>&nbsp;     * @throws InterruptedException Since we&#39;re sleeping in this test.
<i class="no-highlight">54</i>&nbsp;     */
<i class="no-highlight">55</i>&nbsp;    @SuppressWarnings({&quot;magicnumber&quot;, &quot;methodlength&quot;, &quot;PMD.JUnitTestContainsTooManyAsserts&quot;})
<i class="no-highlight">56</i>&nbsp;    @Test
<i class="no-highlight">57</i>&nbsp;    void smokeTest() throws InterruptedException {
<b class="nc"><i class="no-highlight">58</i>&nbsp;        Game game = launcher.getGame();</b>
<b class="nc"><i class="no-highlight">59</i>&nbsp;        Player player = game.getPlayers().get(0);</b>
<i class="no-highlight">60</i>&nbsp;
<i class="no-highlight">61</i>&nbsp;        // start cleanly.
<b class="nc"><i class="no-highlight">62</i>&nbsp;        assertThat(game.isInProgress()).isFalse();</b>
<b class="nc"><i class="no-highlight">63</i>&nbsp;        game.start();</b>
<b class="nc"><i class="no-highlight">64</i>&nbsp;        assertThat(game.isInProgress()).isTrue();</b>
<b class="nc"><i class="no-highlight">65</i>&nbsp;        assertThat(player.getScore()).isZero();</b>
<i class="no-highlight">66</i>&nbsp;
<i class="no-highlight">67</i>&nbsp;        // get points
<b class="nc"><i class="no-highlight">68</i>&nbsp;        game.move(player, Direction.EAST);</b>
<b class="nc"><i class="no-highlight">69</i>&nbsp;        assertThat(player.getScore()).isEqualTo(10);</b>
<i class="no-highlight">70</i>&nbsp;
<i class="no-highlight">71</i>&nbsp;        // now moving back does not change the score
<b class="nc"><i class="no-highlight">72</i>&nbsp;        game.move(player, Direction.WEST);</b>
<b class="nc"><i class="no-highlight">73</i>&nbsp;        assertThat(player.getScore()).isEqualTo(10);</b>
<i class="no-highlight">74</i>&nbsp;
<i class="no-highlight">75</i>&nbsp;        // try to move as far as we can
<b class="nc"><i class="no-highlight">76</i>&nbsp;        move(game, Direction.EAST, 7);</b>
<b class="nc"><i class="no-highlight">77</i>&nbsp;        assertThat(player.getScore()).isEqualTo(60);</b>
<i class="no-highlight">78</i>&nbsp;
<i class="no-highlight">79</i>&nbsp;        // move towards the monsters
<b class="nc"><i class="no-highlight">80</i>&nbsp;        move(game, Direction.NORTH, 6);</b>
<b class="nc"><i class="no-highlight">81</i>&nbsp;        assertThat(player.getScore()).isEqualTo(120);</b>
<i class="no-highlight">82</i>&nbsp;
<i class="no-highlight">83</i>&nbsp;        // no more points to earn here.
<b class="nc"><i class="no-highlight">84</i>&nbsp;        move(game, Direction.WEST, 2);</b>
<b class="nc"><i class="no-highlight">85</i>&nbsp;        assertThat(player.getScore()).isEqualTo(130);</b>
<i class="no-highlight">86</i>&nbsp;
<b class="nc"><i class="no-highlight">87</i>&nbsp;        move(game, Direction.NORTH, 2);</b>
<i class="no-highlight">88</i>&nbsp;
<i class="no-highlight">89</i>&nbsp;        // Sleeping in tests is generally a bad idea.
<i class="no-highlight">90</i>&nbsp;        // Here we do it just to let the monsters move.
<b class="nc"><i class="no-highlight">91</i>&nbsp;        Thread.sleep(500L);</b>
<i class="no-highlight">92</i>&nbsp;
<i class="no-highlight">93</i>&nbsp;        // we&#39;re close to monsters, this will get us killed.
<b class="nc"><i class="no-highlight">94</i>&nbsp;        move(game, Direction.WEST, 10);</b>
<b class="nc"><i class="no-highlight">95</i>&nbsp;        move(game, Direction.EAST, 10);</b>
<i class="no-highlight">96</i>&nbsp;//        assertThat(player.isAlive()).isTrue();
<i class="no-highlight">97</i>&nbsp;
<b class="nc"><i class="no-highlight">98</i>&nbsp;        game.stop();</b>
<b class="nc"><i class="no-highlight">99</i>&nbsp;        assertThat(game.isInProgress()).isFalse();</b>
<i class="no-highlight">100</i>&nbsp;    }
<i class="no-highlight">101</i>&nbsp;
<i class="no-highlight">102</i>&nbsp;    /**
<i class="no-highlight">103</i>&nbsp;     * Make number of moves in given direction.
<i class="no-highlight">104</i>&nbsp;     *
<i class="no-highlight">105</i>&nbsp;     * @param game The game we&#39;re playing
<i class="no-highlight">106</i>&nbsp;     * @param dir The direction to be taken
<i class="no-highlight">107</i>&nbsp;     * @param numSteps The number of steps to take
<i class="no-highlight">108</i>&nbsp;     */
<i class="no-highlight">109</i>&nbsp;    public static void move(Game game, Direction dir, int numSteps) {
<b class="nc"><i class="no-highlight">110</i>&nbsp;        Player player = game.getPlayers().get(0);</b>
<b class="nc"><i class="no-highlight">111</i>&nbsp;        for (int i = 0; i &lt; numSteps; i++) {</b>
<b class="nc"><i class="no-highlight">112</i>&nbsp;            game.move(player, dir);</b>
<i class="no-highlight">113</i>&nbsp;        }
<i class="no-highlight">114</i>&nbsp;    }
<i class="no-highlight">115</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2022-05-22 18:55</div>
</div>
</body>
</html>
